<!--
 * @FilePath     : /study_code/vue2.x/render-jsx1.html
 * @Description  : 渲染函数实现高动态的 标题标签渲染
 * @Date         : 2025-05-03 10:01:04
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-05-03 10:01:11
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <div id="app">
      <anchored-heading :level="4">
        <template v-slot:ac>
          <p>具名插槽</p>
        </template>
        <a name="hello-world" href="#hello-world">Hello world!</a>
      </anchored-heading>
    </div>

    <script src="/vue/dist/vue.min.js"></script>
    <script src="./common.js"></script>

    <script type="text/x-template" id="anchored-heading-template">
      <h1 v-if="level === 1">
        <slot></slot>
      </h1>
      <h2 v-else-if="level === 2">
        <slot></slot>
      </h2>
      <h3 v-else-if="level === 3">
        <slot></slot>
      </h3>
      <h4 v-else-if="level === 4">
        <slot></slot>
      </h4>
      <h5 v-else-if="level === 5">
        <slot></slot>
      </h5>
      <h6 v-else-if="level === 6">
        <slot></slot>
      </h6>
    </script>

    <script>
      /*
      解释：看起来简单多了！这样代码精简很多，但是**需要非常熟悉 Vue 的实例 property**。
      this.$slots 是组件实例对象；
          .default 是组件的默认插槽；
          v-slot 定义的是（名称为 ac的）具名插槽。
      */
      Vue.config.productionTip = false // 阻止 Vue 在启动时生成生产提示

      Vue.component('anchored-heading', {
        // template: "#anchored-heading-template",
        render: function (createElement) {
          console.log('访问插槽', this.$slots)
          return createElement('h' + this.level, this.$slots.default)
        },
        props: {
          level: {
            type: Number,
            required: true,
          },
        },
        created() {
          console.log('无 v-slot 指令的子节点', this.$slots)
        },
      })

      var app = new Vue({
        el: '#app',
        data: function () {
          return {}
        },
      })
    </script>
  </body>
</html>
